package com.tnr.controller;

import com.tnr.dto.EmployeeDto;
import com.tnr.dto.Result;
import com.tnr.service.EmplyeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class EmployeeController {
    @Autowired
    private EmplyeeService emplyeeService;
    @GetMapping("/Emp")
    public Map<String,Object> empList(EmployeeDto employeeDto){
        return emplyeeService.getEmployeeList(employeeDto);
    }

    @PostMapping("/Emp")
    public Result empAdd(@RequestBody EmployeeDto employeeDto){
        try {
            emplyeeService.addEmployee(employeeDto);
            return Result.success("增加成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("增加失败！");
        }
    }
    @PutMapping("/Emp")
    public Result empUpd(@RequestBody EmployeeDto employeeDto){
        try {
            emplyeeService.updEmployee(employeeDto);
            return Result.success("修改成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("修改失败！");
        }
    }
    @DeleteMapping("/Emp")
    public Result empDel(@RequestBody String[] eids){
        try {
            emplyeeService.removeEmployee(eids);
            return Result.success("删除成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("删除失败！");
        }
    }
    @DeleteMapping("/Emp/{eid}")
    public Result emponeDel(@PathVariable("eid") String e_id){
        try {
            emplyeeService.removeEmployee(e_id);
            return Result.success("删除成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("删除失败！");
        }
    }
}
